package oj;

import java.util.Stack;

public class MyQueue {
    private Stack<Integer>  s1;
    private Stack<Integer>  s2;

    public MyQueue() {
        s1=new Stack<>();
        s2=new Stack<>();
    }

    public void push(int x) {
        //当s1为空，将数据存在s1中
        if (s1.isEmpty()) {
            s1.push(x);
        } else {//当s1不为空，就将s1出栈再入栈到s2
            while (!s1.isEmpty()) {
                s2.push(s1.pop());
            }
            //将队尾元素入s1
            s1.push(x);
            //再将s2中的元素出栈入s1
            while (!s2.isEmpty()) {
                s1.push(s2.pop());
            }
        }

    }

    public int pop() {
        return s1.pop();

    }

    public int peek() {
        return s1.peek();

    }

    public boolean empty() {
        return s1.isEmpty();

    }
}
